package Utils;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import dao.DBPool;
import entity.Hotel;

public class SavePicture {
	private QueryRunner runner = new QueryRunner(DBPool.getInstance().getDataSource());
	
	public void save(String fileName,int id) {
		String sql = "update zc_user set img = ? where hotel_id=?";
		Object[] params = {fileName,id};
		int a = 0;
		try {
			a = runner.update(sql, params);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		if (a==0) {
			System.out.println("数据库更改失败...");
		}
		System.out.println("数据库图片存储成功...");
	}
	
	/*
	 * 获取5个随机数字
	 */
	public int getRondom() {
		   int num = (int)((Math.random()*9+1)*1000);
		   return num;		//返回结果是字符串
	}
	
	
	
	public int query(int id) {
		String sql="insert into hotel_reserve (reserve_id,type,see_number,hotel_id) values (null,?,?,?)";
		String[] type= {"基础房","风景房","海景房","基础床房","海景房【风景秀丽】","旅游圣地","高山流水","夜间幽静","干净整洁","天然温泉"};
		int idd = id%10;
		System.out.println(type[idd]);
		Object[] params= {type[idd],getRondom(),id};
		System.out.println("生成的编号--->"+getRondom());
		int num = 0;
		try {
			num = runner.update(sql,params);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return num;
	}
	
	
	
	public static void main(String[] args) {
		SavePicture s = new SavePicture();
		for (int i = 20; i < 263; i++) {
//			s.query(i);
			System.out.println("成功--->"+i);
			System.out.println();
		}
	}
	
}
